//
//  TEHUDViewController.m
//  TintExample
//
//  Created by Kevin Wu on 3/16/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TEHUDViewController.h"

@implementation TEHUDViewController


#pragma mark - Memory

- (id)init {
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)dealloc {
    TTRelease(_imageView);
    [super dealloc];
}

#pragma mark - UIViewController

- (void)loadView {
    [super loadView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addButtonWithTitle:@"Present in view" selector:@selector(presentHUDInView:)];
    [self addButtonWithTitle:@"Present in window" selector:@selector(presentHUDInWindow:)];
    [self addButtonWithTitle:@"Dismiss" selector:@selector(dismissHUD:)];
    
    
    _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"s2.jpg"]];
    _imageView.autoresizingMask = TTViewAutoresizingKeepMargin;
    _imageView.frame = CGRectMake(10, 110, self.view.bounds.size.width-20, self.view.bounds.size.height-120);
    [self.view addSubview:_imageView];
}


- (void)presentHUDInView:(id)sender {
    TTProgressHUD *hud = [TTProgressHUD makeHUDForView:_imageView];
    hud.info = @"Loading ...";
    hud.modeType = TTProgressHUDModeIndeterminate;
    [hud presentAnimated:YES];
}

- (void)presentHUDInWindow:(id)sender {
    TTProgressHUD *hud = [TTProgressHUD makeHUDForView:self.view.window];
    hud.info = @"Loading ...";
    hud.dimBackground = YES;
    hud.modeType = TTProgressHUDModeIndeterminate;
    hud.spacing = 30.0;
    hud.offset = TTPointMake(0.0, -50.0);
    [hud presentAnimated:YES];
    
    [self performSelector:@selector(dismissIt) withObject:nil afterDelay:3.0];
}

- (void)dismissHUD:(id)sender {
    //[TTProgressHUD dismissHUDFromView:_imageView state:YES info:nil animated:YES];
    [TTProgressHUD dismissHUDFromView:_imageView animated:YES];
}

- (void)dismissIt {
    [TTProgressHUD dismissHUDFromView:self.view.window state:NO info:@"HAHA" animated:YES];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return TTIsSupportedOrientation(toInterfaceOrientation);
}

@end
